package com.atguigu.tingshu.handler;

import com.atguigu.tingshu.model.CDCEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * projectName: tingshu-parent
 *
 * @author: 王宝贵
 * time: 2024/11/4 18:36 周一
 * description:
 */
@Slf4j
@Component
@CanalTable(value = "user_info")
public class UserCdcHandler implements EntryHandler<CDCEntity> {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void insert(CDCEntity cdcEntity) {
        EntryHandler.super.insert(cdcEntity);
    }

    @Override
    public void update(CDCEntity before, CDCEntity after) {
        log.info("监听到数据修改,ID:{}", after.getId());

        redisTemplate.delete("sercher:75");
    }

    @Override
    public void delete(CDCEntity cdcEntity) {
        EntryHandler.super.delete(cdcEntity);
    }
}